from django.db.models.signals import post_save
from django.dispatch import receiver

from social.gift.models import GiftRecord


@receiver(post_save, sender=GiftRecord)
def gift_record_post_save(sender, instance: GiftRecord, created, **kwargs):
    if created:
        from social.user.models import GiftWall
        from django.db.models import F
        gift_wall, _ = GiftWall.objects.get_or_create(user_id=instance.to_user_id, gift_id=instance.gift_id)
        gift_wall.count = F('count') + 1
        gift_wall.save(update_fields=['count'])
